package com.yanfan.ccapi.service.impl;

import com.yanfan.ccapi.service.ICcapiDeviceMappingService;
import com.yanfan.ccapicode.dao.DeviceMappingRepository;
import com.yanfan.ccapicode.dao.entity.DeviceMappingDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * 云云对接设备映射Service业务层处理
 *
 * @author kerwincui
 * @date 2025-06-29
 */
@Service
public class CcapiDeviceMappingServiceImpl implements ICcapiDeviceMappingService {
    @Autowired
    private DeviceMappingRepository ccapiDeviceMappingMapper;

    /**
     * 查询云云对接设备映射
     *
     * @param id 云云对接设备映射主键
     * @return 云云对接设备映射
     */
    @Override
    public DeviceMappingDO selectCcapiDeviceMappingById(Long id) {
        return ccapiDeviceMappingMapper.selectById(id);
    }

    /**
     * 查询云云对接设备映射列表
     *
     * @param ccapiDeviceMapping 云云对接设备映射
     * @return 云云对接设备映射
     */
    @Override
    public List<DeviceMappingDO> selectCcapiDeviceMappingList(DeviceMappingDO ccapiDeviceMapping) {
        return ccapiDeviceMappingMapper.selectByCon(ccapiDeviceMapping);
    }

    /**
     * 新增云云对接设备映射
     *
     * @param ccapiDeviceMapping 云云对接设备映射
     * @return 结果
     */
    @Override
    public boolean insertCcapiDeviceMapping(DeviceMappingDO ccapiDeviceMapping) {
        ccapiDeviceMapping.setCreateTime(LocalDateTime.now());
        return ccapiDeviceMappingMapper.insertOrUpdate(ccapiDeviceMapping);
    }

    /**
     * 修改云云对接设备映射
     *
     * @param ccapiDeviceMapping 云云对接设备映射
     * @return 结果
     */
    @Override
    public boolean updateCcapiDeviceMapping(DeviceMappingDO ccapiDeviceMapping) {
        ccapiDeviceMapping.setUpdateTime(LocalDateTime.now());
        return ccapiDeviceMappingMapper.insertOrUpdate(ccapiDeviceMapping);
    }

    /**
     * 批量删除云云对接设备映射
     *
     * @param ids 需要删除的云云对接设备映射主键
     * @return 结果
     */
    @Override
    public boolean deleteCcapiDeviceMappingByIds(Long[] ids) {
        return ccapiDeviceMappingMapper.deleteByIds(Arrays.asList(ids));
    }

    /**
     * 删除云云对接设备映射信息
     *
     * @param id 云云对接设备映射主键
     * @return 结果
     */
    @Override
    public boolean deleteCcapiDeviceMappingById(Long id) {
        return ccapiDeviceMappingMapper.deleteById(id);
    }
}
